//
//  HMAboutViewController.m
//  HowToDo
//
//  Created by 李贺 on 2017/1/5.
//  Copyright © 2017年 KY. All rights reserved.
//

#import "HMAboutViewController.h"
#import "Masonry.h"
#import "UILabel+Addition.h"
#import "HMTreatyViewController.h"

@interface HMAboutViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation HMAboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"关于我们";
    self.view.backgroundColor = [UIColor redColor];

    UITableView * ablouView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    
    [self.view addSubview:ablouView];
    
    ablouView.dataSource =self;
    ablouView.delegate = self;
    
    
    UIView * v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 200)];
    v.backgroundColor = [UIColor clearColor];
    
    UIImageView * image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"show_icon"]];
    
    [v addSubview:image];
    
    //用分类写
    UILabel * lable = [UILabel hm_labelWithText:@"V10.2.1" fontSize:12 color:[UIColor lightGrayColor]];
    
    [v addSubview:lable];
    
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(v);
        make.width.height.offset(60);
    }];
    
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(v);
        make.top.equalTo(image.mas_bottom).offset(8);
    }];

    ablouView.tableHeaderView = v;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return 2;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * cellIdentity = @"cellID";
    
    UITableViewCell * tableViewCell = [tableView dequeueReusableCellWithIdentifier:cellIdentity];
    if (!tableViewCell) {
        tableViewCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentity];
    }
    if(indexPath.section == 0 && indexPath.row == 0){
        tableViewCell.textLabel.text = @"客服电话";
        tableViewCell.detailTextLabel.text = @"010-64711490";
        tableViewCell.detailTextLabel.textColor = [UIColor orangeColor];
    }
    else if(indexPath.section == 0 && indexPath.row == 1){
        tableViewCell.textLabel.text = @"Email";
        tableViewCell.detailTextLabel.text = @"zhanglu@dggroup.cn";
        tableViewCell.detailTextLabel.textColor = [UIColor orangeColor];
    }
    else{
        tableViewCell.textLabel.text = @"服务使用协议";
    }
    return tableViewCell;
}

///取消选中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(indexPath.section == 0 && indexPath.row == 0){
        //拨打电话
        [self callPhone];
    }
    else if(indexPath.section == 1){
        //跳转到webview
        HMTreatyViewController * vc = [[HMTreatyViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

///点击cell拨打电话
- (void)callPhone{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle: @"联系十万个为什么客服"                                                                             message: @"打电话给十万个为什么客服"                                                                       preferredStyle:UIAlertControllerStyleAlert];
    
    [alertController addAction: [UIAlertAction actionWithTitle: @"确定" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        //打电话
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://01064711490"] options:@{} completionHandler:nil];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
    
}



@end
